package com.song.day06.ch6_9;

import java.util.concurrent.atomic.AtomicIntegerArray;

public class Main {
	
	
	public static void main(String[] args) {
		
		final int THREADS =100;
		AtomicIntegerArray vector = new AtomicIntegerArray(1000);
		
		Incrementer incrementer = new Incrementer(vector);
		Decrementer derementer = new Decrementer(vector);
		
		Thread ithread[] = new Thread[THREADS];
		Thread dthread[] = new Thread[THREADS];
		
		for(int i=0;i<THREADS;i++)
		{
			ithread[i] = new Thread(incrementer);
			dthread[i] = new Thread(derementer);
			
			ithread[i].start();
			dthread[i].start();
		}
		
		for(int i=0;i<100;i++)
		{
			try {
				ithread[i].join();;
				dthread[i].join();;
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		for(int i=0;i<vector.length();i++)
		{
			if(vector.get(i)!=0){
				System.out.println("Vector["+i+"]: "+vector.get(i));
			}
		}
		
		System.out.println(" Main : End !");
	}
}
